export class Result<T> {
    message: string = 'ok';
    data?: T;
    code: number = 1

    isSuccess(): boolean {
        return this.code == 1
    }


    buildMessage(message: string = "ok"): this {
        this.message = message
        return this
    }

    buildCode(code: number): this {
        this.code = code
        return this
    }

    buildData(data: T): this {
        this.data = data
        return this
    }

    static fail(message: string) {
        return new Result().buildCode(-1).buildMessage(message)
    }

    static success<T>(data: T) {
        return new Result().buildCode(1).buildMessage('success').buildData(data)
    }

    static successWithCode<T>(data: T, code: number) {
        return new Result().buildCode(code).buildMessage('success').buildData(data)
    }

    static successWithCodeAndMsg<T>(data: T, code: number, message: string) {
        return new Result().buildMessage(message).buildCode(code).buildData(data)
    }
}